#
# makefile
#
# Compilation options for various compilers, with the best optimizations I know sofar.
#
# If you have a CPU supporting popcount (Intel Nehalem (i7) or AMD Barcelona),
# add -DPOPCOUNT to you favorite compiler option set.
#

# gcc 4.x x86-64 for linux & Mac OS X
L64_GCC4_FLAGS = -std=c99 -pedantic -W -Wall -pipe\
            -DNDEBUG -DUSE_GAS_X64 -D_GNU_SOURCE=1\
            -m64 -O3 -mtune=generic -ffast-math -fwhole-program -lm -pthread 

# gcc 3.x (& 4.0) x86-64 for linux & Mac OS X
L64_GCC3_FLAGS = -std=c99 -pedantic -W -Wall -pipe\
            -DNDEBUG -DUSE_GAS_X64 -D_GNU_SOURCE=1\
            -m64 -O3 -ffast-math -lm -pthread 

# gcc x86 (32 bits) for linux
L32_GCC_FLAGS = -std=c99 -pedantic -W -Wall -pipe\
            -DNDEBUG -DUSE_GAS_X86 -DUSE_GAS_MMX -D_GNU_SOURCE=1\
            -m32 -O3 -fomit-frame-pointer -ffast-math -lm -pthread 

# gcc for PowerPC-64 for linux & Mac OS X
PPC64_FLAGS = -std=c99 -pedantic -W -Wall -pipe\
            -DNDEBUG -D_GNU_SOURCE=1 DUSE_TYPE_PUNING=0\
            -mpowerpc64 -O3 -ffast-math -lm -pthread 

# gcc with debug flags & low optimization
DEBUG_FLAGS = -std=c99 -pedantic -W -Wall -pipe\
            -DDEBUG -DUSE_GAS_X64 -D_GNU_SOURCE=1\
            -O0 -ffast-math -g -lm -pthread 

## ICC for Linux x86-64
X64_ICC_FLAGS = -std=c99 -Wall -Wcheck -w0\
                -DNDEBUG -DUSE_GAS_X64 -DRCD=0.0 -D_GNU_SOURCE=1\
                -O3 -xHOST -rcd -align -falign-functions -ansi-alias\
                -lm -pthread

## ICC for Linux x86-64
X64_ICC_PROF_FLAGS = $(X64_ICC_FLAGS) -fno-inline-functions

## ICC for Linux x86-64
X64_ICC_DBG_FLAGS = -std=c99 -Wall -Wcheck -w0\
                -DDEBUG -DUSE_GAS_X64 -DRCD=0.0 -D_GNU_SOURCE=1\
                -g -O2 -xHOST -align -falign-functions -ansi-alias -rcd -lm -pthread

# pcc for Linux x86-64 (bad include)
L64_PCC_FLAGS = -std=c99\
                -I /usr/lib64/pcc/x86_64-unknown-linux-gnu/0.9.9/include/\
                -DNDEBUG -D_GNU_SOURCE=1 -D__unix__\
                -lm -pthread 

# clang for Linux x86-64 (-O4 failed)
L64_CLANG_FLAGS = -std=c99 -pedantic -W -Wall\
                  -I /usr/lib/clang/1.0/include/\
                  -DNDEBUG -DUSE_GAS_X64 -D_GNU_SOURCE=1\
                  -m64 -O3 -ffast-math -lm -pthread 

# clang for Mac x86-64 (-O4 OK)
M64_CLANG_FLAGS = -std=c99 -pedantic -W -Wall\
                  -DNDEBUG -DUSE_GAS_X64 -D_GNU_SOURCE=1\
                  -m64 -O4 -pthread

# gcc 4.x x86-64 for Mac OS X
M64_GCC4_FLAGS = -std=c99 -pedantic -W -Wall -pipe\
            -DNDEBUG -DUSE_GAS_X64 -D_GNU_SOURCE=1 -mmacosx-version-min=10.4\
            -m64 -O3 -ffast-math -fwhole-program -lm -pthread 

# gcc 3.x (& 4.0) x86-64 for Mac OS X
M64_GCC3_FLAGS = -std=c99 -pedantic -W -Wall -pipe\
            -DNDEBUG -DUSE_GAS_X64 -D_GNU_SOURCE=1 -mmacosx-version-min=10.4\
            -m64 -O3 -ffast-math -lm -pthread 

# gcc 4.x x86 (32bits) for Mac OS X
M32_GCC_FLAGS = -std=c99 -pedantic -W -Wall -pipe\
            -DNDEBUG -DUSE_GAS_X86 -DUSE_GAS_MMX -D_GNU_SOURCE=1 -mmacosx-version-min=10.4\
            -m32 -O3 -fomit-frame-pointer -ffast-math -lm -pthread 

# Mingw-w86 cross compiler for Windows (7 or Vista or XP?) 32bits
W86_X_FLAGS = -std=c99 -pedantic -W -Wall -pipe -march=i686\
            -DUSE_GAS_X86 -DNDEBUG -D__USE_MINGW_ANSI_STDIO -D_GNU_SOURCE=1\
            -DUSE_PTHREAD -m32 -O3 -fomit-frame-pointer -ffast-math -fwhole-program -s -static

# Mingw-w64 for Windows (7 or Vista or XP?) 64bits
W64_GCC_FLAGS = -std=c99 -pedantic -W -Wall -pipe\
            -DUSE_GAS_X64 -DNDEBUG -D__USE_MINGW_ANSI_STDIO -D_GNU_SOURCE=1\
            -mthreads -DUSE_PTHREAD -I /auxlibs/include -L /auxlibs/lib -lpthread\
            -m64 -O3 -ffast-math -fwhole-program -s -static

# Pelles C Compiler for Windows (7 or Vista) 64bits.
W64_POCC_FLAGS = -Tamd64-coff -MT -Ot -Ox -Ob2 -fp:fast -W0 -Gr -Ze -DDEFINE_CONDITION_VARIABLE=1

# Microsoft Visual C++ 2008 or better for Windows (7 or Vista) 64bits.
W64_VC_FLAGS = /I"..\include" /Ox /Ob2 /GL /fp:fast\
               /D "NDEBUG" /D "inline=__inline" /D "__func__=__FUNCTION__" /D "USE_MSVC_X64"\
               /MT 

# Microsoft Visual C++ 2008 of better for Windows (7 or Vista) 32bits.
W86_VC_FLAGS = /I"..\include" /Ox /Ob2 /GL /fp:fast\
               /D "NDEBUG" /D "inline=__inline" /D "__func__=__FUNCTION__"\
               /MT

# RULES
# Linux
linux-gcc3-x64:
	gcc $(L64_GCC3_FLAGS) all.c -s -o ../bin/lEdax

linux-gcc4-x64:
	gcc $(L64_GCC4_FLAGS) all.c -s -o ../bin/lEdax

debug:
	gcc $(DEBUG_FLAGS) all.c -o ../bin/lEdax

linux-icc-x64:
	LANG="C" icc all.c $(X64_ICC_FLAGS) -o ../bin/lEdax

linux-icc-tune-x64:
	LANG="C" icc all.c $(X64_ICC_FLAGS) -DTUNE -o ../bin/lEdax

linux-icc-prof-x64:
	LANG="C" icc all.c $(X64_ICC_PROF_FLAGS) -o ../bin/lEdax

linux-icc-debug-x64:
	LANG="C" icc all.c $(X64_ICC_DBG_FLAGS) -o ../bin/lEdax

linux-icc-pgo-x64:
	LANG="C" icc -prof-gen all.c $(X64_ICC_FLAGS) -o ../bin/lEdax
	cd ../bin; ./lEdax -n 4 -l 60 -solve problem/fforum-20-39.script
	cd ../bin; ./lEdax -n 4 -l 21 -auto-store on -auto-start on -repeat 3 -auto-quit on -mode 2 -book-file book.pgo
	rm -f ../bin/book.pgo
	LANG="C" icc  -prof-use all.c -s $(X64_ICC_FLAGS) -o ../bin/lEdax

linux-gcc4-pgo-x64:
	gcc $(L64_GCC4_FLAGS) -fprofile-generate all.c -o ../bin/lEdax
	cd ../bin; ./lEdax -l 60 -solve problem/fforum-20-39.script; cd ../src
	cd ../bin; ./lEdax -l 21 -auto-store on -auto-start on -repeat 3 -auto-quit on -mode 2 -book-file book.pgo
	rm -f ../bin/book.pgo ../bin/book.pgo.store
	gcc $(L64_GCC4_FLAGS) -fprofile-correction -fprofile-use all.c -s -o ../bin/lEdax

linux-gcc3-pgo-x64:
	gcc $(L64_GCC3_FLAGS) -fprofile-generate all.c -o ../bin/lEdax
	cd ../bin; ./lEdax -n 1 -l 60 -solve problem/fforum-20-39.script; cd ../src
	cd ../bin; ./lEdax -n 1 -l 21 -auto-store on -auto-start on -repeat 3 -auto-quit on -mode 2 -book-file book.pgo
	rm -f ../bin/book.pgo
	gcc $(L64_GCC3_FLAGS) -fprofile-use all.c -o ../bin/lEdax

linux-gcc-tune-x64:
	LANG="C" gcc all.c $(X64_ICC_FLAGS) -DTUNE -s -o ../bin/lEdax

linux-clang-x64:
	clang $(L64_CLANG_FLAGS) all.c -s -o ../bin/lEdax

linux-pcc-x64:
	pcc $(L64_PCC_FLAGS) all.c -s -o ../bin/lEdax

linux-gcc-x86:
	gcc $(L32_GCC_FLAGS) all.c -g -o ../bin/lEdax-x86



# Mac
mac-gcc4-x64:
	gcc $(M64_GCC4_FLAGS) all.c -o ../bin/mEdax

mac-gcc4-pgo-x64:
	gcc $(M64_GCC4_FLAGS) -fprofile-generate all.c -o ../bin/mEdax
	cd ../bin; ./mEdax -n 1 -l 60 -solve problem/fforum-20-39.script; cd ../src
	cd ../bin; ./mEdax -n 1 -l 21 -auto-store on -auto-start on -repeat 3 -auto-quit on -mode 2 -book-file book.pgo
	rm -f ../bin/book.pgo ../bin/book.pgo.store
	gcc $(M64_GCC4_FLAGS) -fprofile-use all.c -o ../bin/mEdax

mac-gcc3-x64:
	gcc $(M64_GCC3_FLAGS) all.c -o ../bin/mEdax

mac-gcc3-pgo-x64:
	gcc $(M64_GCC3_FLAGS) -fprofile-generate all.c -o ../bin/mEdax
	cd ../bin; ./mEdax -n 1 -l 60 -solve problem/fforum-20-39.script; cd ../src
	gcc $(M64_GCC3_FLAGS) -fprofile-use all.c -o ../bin/mEdax

mac-gcc4-ppc64:
	gcc $(PPC64_FLAGS) all.c -o ../bin/mEdax-ppc64

mac-icc-x64:
	icc all.c $(X64_ICC_FLAGS) -o ../bin/edax

mac-icc-pgo-x64:
	icc all.c $(X64_ICC_FLAGS) -prof-gen -o ../bin/mEdax
	cd ../bin; ./mEdax -n 4 -l 60 -solve problem/fforum-20-39.script; cd ../src
	icc all.c $(X64_ICC_FLAGS) -prof-use -s -o ../bin/mEdax

mac-clang-x64:
	clang $(M64_CLANG_FLAGS) all.c -o ../bin/mEdax

mac-debug:
	gcc $(DEBUG_FLAGS) all.c -o ../bin/mEdax

# Windows 
win-gcc-x64:
	gcc $(W64_GCC_FLAGS) all.c -o ../bin/wEdax.exe

win-gcc-x86:
	gcc $(W86_X_FLAGS) all.c -o ../bin/wEdax.exe -lpthread

win-pocc-x64:
	pocc $(W64_POCC_FLAGS) all.c /Fo all.obj
	polink all.obj /out:../bin/wEdax-pocc

win-vc-x64:
	cl $(W64_VC_FLAGS) all.c /Fe..\bin\wEdax.exe

win-vc-x86:
	cl $(W86_VC_FLAGS) all.c /Fe..\bin\wEdax.exe

win-vc-pgo-x64:
	set VCPROFILE_PATH=..\src
	cl $(W64_VC_FLAGS) all.c /Fe..\bin\wEdax.exe /link /ltcg:pgi /machine:x64
	cd ..\bin
	wEdax.exe -n 4 -l 60 -solve problem/fforum-20-39.script
	cd ..\src
	link all.obj /out:..\bin\wEdax.exe /ltcg:pgo /machine:x64

win-cross-x86:
	i686-pc-mingw32-gcc $(W86_X_FLAGS) all.c -o ../bin/wEdax-x86.exe -lpthread

clean:
	rm -f pgopti* *.dyn *~


